home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Browsers, Managers & Extensions / Mozilla Weave 0.2.7 / latest-weave.xpi / chrome / sync.jar / content / share.js < prev    next >
Text File  |  2008-07-08  |  5KB  |  103 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is Bookmarks Sync.
  15.  *
  16.  * The Initial Developer of the Original Code is Mozilla.
  17.  * Portions created by the Initial Developer are Copyright (C) 2007
  18.  * the Initial Developer. All Rights Reserved.
  19.  *
  20.  * Contributor(s):
  21.  *  Dan Mills <thunder@mozilla.com>
  22.  *  Chris Beard <cbeard@mozilla.com>
  23.  *
  24.  * Alternatively, the contents of this file may be used under the terms of
  25.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  26.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.  * in which case the provisions of the GPL or the LGPL are applicable instead
  28.  * of those above. If you wish to allow use of your version of this file only
  29.  * under the terms of either the GPL or the LGPL, and not to allow others to
  30.  * use your version of this file under the terms of the MPL, indicate your
  31.  * decision by deleting the provisions above and replace them with the notice
  32.  * and other provisions required by the GPL or the LGPL. If you do not delete
  33.  * the provisions above, a recipient may use your version of this file under
  34.  * the terms of any one of the MPL, the GPL or the LGPL.
  35.  *
  36.  * ***** END LICENSE BLOCK ***** */
  37.  
  38. function Share() {
  39.   this._init();
  40. }
  41. Share.prototype = {
  42.   _init: function Share__init() {
  43.     /* Immediately upon popping up the dialog box, set the folder-msg
  44.        label in the dialog box to reflect the name of the folder that
  45.        was selected for sharing: */
  46.     this._selectedMenuFolder = window.arguments[0];
  47.     let folderName = this._selectedMenuFolder.getAttribute("label");
  48.     let fullString = this._stringBundle.getFormattedString( "folder.message",
  49.                                 [folderName] );
  50.     document.getElementById("folder-msg").setAttribute("value", fullString);
  51.   },
  52.   get _stringBundle() {
  53.     let stringBundle = document.getElementById("weaveStringBundle");
  54.     this.__defineGetter__("_stringBundle",
  55.                           function() { return stringBundle; });
  56.     return this._stringBundle;
  57.   },
  58.   doShare: function Share_doShare(event) {
  59.     /* This is called when the user clicks the Share button in the
  60.        dialog box.*/
  61.     /* Start the active display widgets (throbber, label) to let the user know
  62.        that something is happening: */
  63.     let labelStr = this._stringBundle.getString("status.working");
  64.     let label = document.getElementById("status.label");
  65.     label.setAttribute("value", labelStr);
  66.     label.setAttribute("hidden", false);
  67.     document.getElementById("throbber").setAttribute("hidden", true);
  68.     document.getElementById("throbber-active").setAttribute("hidden", false);
  69.     let self = this;
  70.     /* tell the weave service to share the chosen bookmark folder with
  71.        the user specified in the "username' input field. */
  72.     this._username = document.getElementById("username").value;
  73.     Weave.Service.shareData("bookmarks",
  74.                 true, // turn share on
  75.                             function(ret) { self.shareCb(ret); },
  76.                             this._selectedMenuFolder.node.itemId,
  77.                             this._username);
  78.     this.shareCb( true );
  79.   },
  80.   shareCb: function Share_Callback(ret) {
  81.     /* Called when share has either succeded or failed.
  82.        First, set the active display widgets to stop spinning and show
  83.        success or failure.
  84.  
  85.        LONGTERM TODO Consider redesign of the notification ui: a progress bar?
  86.        Dismiss the window immediately and give a separate notification
  87.        when we're done?
  88.     */
  89.     document.getElementById("throbber").setAttribute("hidden", false);
  90.     document.getElementById("throbber-active").setAttribute("hidden", true);
  91.     let label = ret?
  92.       this._stringBundle.getString("status.ok") :
  93.       this._stringBundle.getString("status.error");
  94.     document.getElementById("status.label").setAttribute("value", label);
  95.   },
  96.   doCancel: function Share_doCancel(event) { return true; },
  97.   shutDown: function Share_shutDown(event) {}
  98. };
  99.  
  100. let gShare;
  101. window.addEventListener("load", function(e) { gShare = new Share(); }, false);
  102. window.addEventListener("unload", function(e) { gShare.shutDown(e); }, false);
  103.